import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { TodayNotTipUtil } from "../../../common/TodayNotTipUtil";
import { TodayNoTipsConst } from "../../../component/gconst/TodayNoTipsConst";
import { Language } from "../../../../extend/language/Language";
import { Alert } from "../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ObjCreate } from "../common/ObjCreate";
import { WuXingRefreshList } from "./WuXingRefreshList";
import { WuXingPlayerInfo } from "../../model/wuxing/WuXingPlayerInfo";
import { Global } from "../../../../com/gengine/global/Global";
import { EffectManager } from "../../manager/EffectManager";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { GButton } from "../../../../com/mui/controls/GButton";
import { LineBox } from "../guide/LineBox";
type int = number;
//class WuXingGroupRefreshRender
    
    export  class WuXingGroupRefreshRender extends GCellRenderer
    {
        constructor()
        {
            super();
            this.initUI();
            return;
        }

        /* internal  */onOptClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._info && !(this._info.getNewVitalsAddition(this._index) == 0)) 
            {
                if (this._info.vitalsAddition > this._info.getNewVitalsAddition(this._index)) 
                {
                    TodayNotTipUtil.toDayNotTip(TodayNoTipsConst.WuXingReplaceNotTip, this.replaceReq, Language.getString(26418), null, Alert.OK | Alert.CANCEL);
                }
                else 
                {
                    this.replaceReq();
                }
            }
            return;
        }

        /* internal  */replaceReq(): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.WuXingAttrReplaceReq, this._index));
            return;
        }

        protected initUI(): void
        {
            this._bg = ObjCreate.createBg(0, 0, this.width, this.height, this);
            this._optBtn = ObjCreate.createGButton(Language.getString(26377), 0, 0, 88, 22, this);
            this._optBtn.x = (this.width - this._optBtn.width) / 2;
            this._optBtn.y = this.height - 28;
            this._optBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOptClickHandler);
            this._optBtn.drawNow();
            this._attrList = new WuXingRefreshList(1, this.width, 152, false, 18);
            addChild(this._attrList);
            return;
        }

        protected clear(): void
        {
            this._attrList.clearAttrList();
            this.glowEffect(false);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            if (data != null) 
            {
                this._info = data.info as WuXingPlayerInfo;
                this._index = int(data.index);
                this._attrList.updateData(this._info, this._index);
                this._attrList.invalidate();
                Global.instance.callLater(this.callLater);
            }
            else 
            {
                this.clear();
                this._info = null;
                this._index = -1;
                Global.instance.callLater(this.callLater);
            }
            return;
        }

        /* internal  */callLater(): void
        {
            if (this._info) 
            {
                if (this._info.getNewVitalsAddition(this._index) > 0) 
                {
                    this._optBtn.enabled = true;
                    if (this._info.isMaxNewVitalsAddition(this._index) && this._info.getNewVitalsAddition(this._index) > this._info.vitalsAddition) 
                    {
                        this.glowEffect();
                    }
                    else 
                    {
                        this.glowEffect(false);
                    }
                }
                else 
                {
                    this._optBtn.enabled = false;
                    this.glowEffect(false);
                }
            }
            else 
            {
                this._optBtn.enabled = false;
                this.glowEffect(false);
            }
            this._optBtn.drawNow();
            return;
        }

        /* internal  */glowEffect(arg1: Boolean=true): void
        {
            if (arg1) 
            {
                if (!this._lineBox) 
                {
                    this._lineBox = EffectManager.getLineBox(this.width, this.height, null, 0.5, 2);
                    addChild(this._lineBox);
                }
                this._lineBox.x = 0;
                this._lineBox.y = 0;
            }
            else if (this._lineBox) 
            {
                EffectManager.disposeLineBox(this._lineBox);
                this._lineBox = null;
            }
            return;
        }

        public /* override */ setSize(arg1: number, arg2: number): void
        {
            super.setSize(this.width, this.height);
            return;
        }

        public /* override */ get height(): number
        {
            return 185;
        }

        public /* override */ get width(): number
        {
            return 148;
        }

        protected /* var */_info: WuXingPlayerInfo;

        protected /* var */_index: int;

        protected /* var */_bg: ScaleBitmap;

        protected /* var */_attrList: WuXingRefreshList;

        protected /* var */_optBtn: GButton;

        /* internal */ /* var */_lineBox: LineBox;
    }
